<?php

namespace app\admin\controller\business;

use app\common\controller\AdminController;
use EasyAdmin\annotation\ControllerAnnotation;
use EasyAdmin\annotation\NodeAnotation;
use think\App;

/**
 * @ControllerAnnotation(title="business_district_admin")
 */
class DistrictAdmin extends AdminController
{

    use \app\admin\traits\Curd;

    public function __construct(App $app)
    {
        parent::__construct($app);

        $this->model = new \app\common\model\BusinessDistrictAdmin();
        
    }

    /**
     * @NodeAnotation(title="列表")
     */
    public function index()
    {
        $data = input();
        if ($this->request->isAjax()) {
            if (input('selectFields')) {
                return $this->selectList();
            }
            list($page, $limit, $where) = $this->buildTableParames();
            $where['da.district_id'] = input('district_id',0);
            $count = $this->model
                ->alias('da')
                ->where($where)
                ->count();
            $list = $this->model
                ->alias('da')
                ->join('pm_business_district d','da.district_id = d.id','right')
                ->join('pm_user u','da.user_id= u.id','right')
                ->where($where)
                ->page($page, $limit)
                ->order($this->sort)
                ->field('da.*,d.name,u.nickname,u.phone')
//                ->buildSql();
                ->select();
//            dd($list);
            $data = [
                'code'  => 0,
                'msg'   => '',
                'count' => $count,
                'data'  => $list,
            ];
            return json($data);
        }
        $this->assign('row', $data);
        return $this->fetch();
    }

}